#include <iostream>
#include "Simplex.h"
#include "Node.h"
#include "TopologicalObject.h"

using namespace std;

int TopologicalObject::Compare (TopologicalObject *const &n1,TopologicalObject *const &n2)
{
	return n1->Number ()  - n2->Number () ;
}

TopologicalObject::TopologicalObject (Simplex ts)
			: set_(ts)
{
	number_ =-1;
	mate_ = 0;
	valid_b_ = false;
}

TopologicalObject::~TopologicalObject ()
{
}

char const *TopologicalObject::Name (SimplexType g)
{
	switch (g){
	  case NODE: 
		  return "node";
	  case EDGE: 
		  return "edge";
	  case TRIANGLE: 
		  return "triangle";
	  case TETRAHEDRON: 
		  return "tetrahedron";
	  default:
		  return 0;
	}
}


const char *TopologicalObject::Name () const
{
	return TopologicalObject::Name (set_.Type ());
}


bool TopologicalObject::ContainsB (Node *np) const
{
	return set_.ContainsB (np);
}


bool TopologicalObject::ValidNodes ()const
{
	return set_.ValidNodes () &&number_ >=0;

}

bool TopologicalObject::Valid () const
{
	return valid_b_ && ValidNodes ();
}

bool FixedB (TopologicalObject *to)
{
	bool f = false;
	for (int i =0;  i < 4; i++)
		f = f || to->GetNode (i)->FixedB ();
	return f;
}
